package com.app.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.app.controller.importExcel.ImportExcelListener;
import com.app.mapper.AmmunitionMapper;
import com.app.mapper.CategoryMapper;
import com.app.mapper.CategoryPhoneMapper;
import com.app.model.AmmunitionModel;
import com.app.model.CategoryModel;
import com.app.model.DepartmentModel;
import com.app.model.ProtectionPointModel;
import com.app.service.AmmunitionService;
import com.app.service.CategoryService;
import com.app.service.DepartmentService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.util.TestFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.thymeleaf.util.ListUtils;
import org.thymeleaf.util.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

@Service
public class AmmunitionServiceImpl implements AmmunitionService {
    @Autowired
    private AmmunitionMapper ammunitionMapper;

    @Override
    public void insert(AmmunitionModel ammunitionModel) {
        ammunitionMapper.insert(ammunitionModel);
    }
//批量删除弹药
    @Override
    public Result<Object> deleteAmmunitionBatchByIds(String ids) {
        // 参数校验
        if (StringUtils.isEmpty(ids)) {
            return Result.success("参数为空，无需删除");
        }
        List<Integer> idsList = Arrays.stream(ids.split(","))
                .map(Integer::valueOf)
                .collect(Collectors.toList());
        // 批量删除
        if (!ListUtils.isEmpty(idsList)) {
            ammunitionMapper.deleteBatchIds(idsList);
            return Result.success("批量删除成功");
        } else {
            return Result.success("批量删除失败，数据为空");
        }
    }
}
